package com.atxiao.demo.bean;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result {
    /**
     * 返回编码
     */
    private Integer code;

    /**
     * 返回消息
     */
    private String message;

    /**
     * 存放数据
     */
    private Map<String, Object> data = new HashMap<String, Object>();

    public static Result success() {
        Result r = new Result();
        r.setCode(200);
        r.setMessage("操作成功");
        return r;
    }

    public static Result errorResult() {
        Result r = new Result();
        r.setCode(501);
        r.setMessage("操作失败");
        return r;
    }
    public static Result success(String message) {
        Result r = new Result();
        r.setCode(200);
        r.setMessage(message);
        return r;
    }

    public static Result errorResult(String message) {
        Result r = new Result();
        r.setCode(501);
        r.setMessage(message);
        return r;
    }



    public static Result success(String message,Map info) {
        Result r = new Result();
        r.setCode(200);
        r.setMessage(message);
        r.setData(info);
        return r;
    }

    public static Result errorResult(String message,Map info) {
        Result r = new Result();
        r.setCode(501);
        r.setMessage(message);
        r.setData(info);
        return r;
    }

    public Result() {
    }

    public Result(Integer code, String message, Map<String, Object> data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
